package request;

import javax.servlet.ServletException;
import javax.servlet.ServletInputStream;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.BufferedReader;
import java.io.IOException;

/**
 * 获取请求体中的请求参数
 * 请求体：只有POST请求方式才有请求体，在请求体中封装了post请求的请求参数
 * @author Mc.Chai
 * @program: JavaWeb
 * @create 2022-03-20-21:18 21:18
 */
@WebServlet("/myRequest5")
public class MyRequest5 extends HttpServlet {
    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        //获取字符流
        BufferedReader reader = request.getReader();

        while (true){
            //读取数据
            String s = reader.readLine();
            if (s==null) break;
            System.out.println(s);
        }
    }

    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        System.out.println("myRequest5被访问......");
    }
}
